package com.efuture.androidmvvmdemo.viewmodel

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.efuture.androidmvvmdemo.base.BaseModel
import com.efuture.androidmvvmdemo.net.ApiParameter
import com.efuture.androidmvvmdemo.net.NetService
import com.efuture.netrequestdemo.bean.User
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

/**

 *@description:TODO
 * @author: zhaoshanshan
 * @date: 2022/3/27 1:14 下午

 */
class LoginViewModel(application: Application) : AndroidViewModel(application) {

    val loginData = MutableLiveData<User>()
    val userName = MutableLiveData<String>()
    val passWord = MutableLiveData<String>()

    fun loginUser(userName:String,passWord:String){
        //开始调用网络

        viewModelScope.launch(Dispatchers.Main) {
            //登录
            val loginUser: User? = NetService.request(ApiParameter.loginUser(userName,passWord),"正在登录中...")
            loginData.postValue(loginUser)
        }
    }
}